﻿//13.Write a program that reverses the words in given sentence.
//Example: "C# is not C++, not PHP and not Delphi!" -> "Delphi not and PHP, not C++ not is C#!".

using System;
using System.Text;

namespace ReverseWords
{
    class ReverseWords
    {
        static void Main()
        {
            string text = "C# is not C++, not PHP and not Delphi!";
            Console.WriteLine(ReversedWords(text));
        }

        private static string ReversedWords(string sentence)
        {
            string[] words = sentence.Split(new char[] { ' ', ',', '!', '?', '.' }, StringSplitOptions.RemoveEmptyEntries);
            string[] signs = sentence.Split(words, StringSplitOptions.RemoveEmptyEntries);

            Array.Reverse(words);

            StringBuilder reverseSentence = new StringBuilder();

            for (int i = 0; i < words.Length; i++)
            {
                reverseSentence.Append(words[i] + signs[i]);
            }
            return reverseSentence.ToString();
        }
    }
}
